var content = { defaultgrade: "初中", defaultname: "张三" };
var template = "我是一名{{defaultgrade}}学生，我的名字叫{{defaultname}}";
const rg = /\{\{[a-zA-Z]+\}\}/g;
let res1 = template.match(rg); //[ '{{defaultgrade}}', '{{defaultname}}' ]
let matcharr = [];
let t = 0;
for (let i of res1) {
  matcharr[t++] = i.slice(2, i.length - 2);
}
console.log(matcharr);
let res = template.replace(rg, content[matcharr[1]]);
console.log(res);